package org.datamining.guha.rule;

import java.util.List;
import org.datamining.guha.model.literal.Literal;

/**
 * Basic implementation of Rule interface.
 * 
 * @author Lukas Vlcek
 *
 */
public class RuleImpl implements Rule {

    private List<Literal> antecedents;
    private List<Literal> succedents;
    
    private double support;
    private double confidence;
    
    /** Creates a new instance of Rule */
    public RuleImpl(List<Literal> antecedents, List<Literal> succedents, double support, double confidence) {
        this.antecedents = antecedents;
        this.succedents = succedents;
        this.support = support;
        this.confidence = confidence;
    }
    
    public List<Literal> getAntecedents() {
    	return antecedents;
    }
    
    public List<Literal> getSuccedents() {
    	return succedents;
    }
    
	public String toString() {
        StringBuffer sb = new StringBuffer();
        
        sb.append("Supp["+support+"] ");
        sb.append("Conf["+confidence+"] ");
        
        for (int i = 0; i < antecedents.size(); i++) {
            Literal l = (Literal) antecedents.get(i);
            sb.append(l + " ");
        }
        
        sb.append("=> ");
        
        for (int i = 0; i < succedents.size(); i++) {
            Literal l = (Literal) succedents.get(i);
            sb.append(l + " ");
        }
        
        return sb.toString();
	}
	
    public String toHTML() {
        StringBuffer sb = new StringBuffer();
        
        sb.append("</tr>");
        
        sb.append("<td align='right'>");
        for (int i = 0; i < antecedents.size(); i++) {
            Literal l = (Literal) antecedents.get(i);
            sb.append(l + " ");
        }
        sb.append("</td>");
        sb.append("<td>=&gt;</td>");
        sb.append("<td>");
        for (int i = 0; i < succedents.size(); i++) {
            Literal l = (Literal) succedents.get(i);
            sb.append(l + " ");
        }
        sb.append("</td>");
        
        sb.append("<td>"+support+"</td>");
        sb.append("<td>"+confidence+"</td>");
        
        sb.append("</tr>");
        
        return sb.toString();
    }
}
